package com.blog.cloud.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blog.cloud.api.dto.BlogDto;
import com.blog.cloud.api.entity.Blog;
import com.blog.cloud.service.mapper.BlogMapper;
import com.blog.cloud.service.service.BlogService;
import org.springframework.stereotype.Service;

/**
 * 博客表(Blog)表服务实现类
 *
 * @author 龙茶清欢
 * @since 2023-02-27 19:09:33
 */
@Service("blogService")
public class BlogServiceImpl extends ServiceImpl<BlogMapper, Blog> implements BlogService {

    @Override
    public Page<Blog> findBlogByPage(BlogDto blogDto) {
        Page<Blog> page = new Page<>();

        if (blogDto.getSize() > 0 && blogDto.getCurrent() > 0) {
            page.setCurrent(blogDto.getCurrent());
            page.setSize(blogDto.getSize());
        }

        LambdaQueryWrapper<Blog> wrapper = new LambdaQueryWrapper<>();
        if (blogDto.getBlogId() != null) {
            wrapper.eq(Blog::getBlogId, blogDto.getBlogId());
        }
        wrapper.orderByDesc(Blog::getUpdateTime);

        return this.baseMapper.selectPage(page, wrapper);
    }

}

